package xiaohongshu

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"marketing-server/global"
	"marketing-server/model/common/response"
	"marketing-server/model/marketing/xiaohongshu"
	xiaohongshuReq "marketing-server/model/marketing/xiaohongshu/request"
)

type XhsPreAuthCodeApi struct{}

// CreateXhsPreAuthCode 创建xhsPreAuthCode表
// @Tags XhsPreAuthCode
// @Summary 创建xhsPreAuthCode表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsPreAuthCode true "创建xhsPreAuthCode表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /xhsPreAuthCode/createXhsPreAuthCode [post]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) CreateXhsPreAuthCode(c *gin.Context) {
	var xhsPreAuthCode xiaohongshu.XhsPreAuthCode
	err := c.ShouldBindJSON(&xhsPreAuthCode)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsPreAuthCodeService.CreateXhsPreAuthCode(&xhsPreAuthCode)
	if err != nil {
		global.MS_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteXhsPreAuthCode 删除xhsPreAuthCode表
// @Tags XhsPreAuthCode
// @Summary 删除xhsPreAuthCode表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsPreAuthCode true "删除xhsPreAuthCode表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /xhsPreAuthCode/deleteXhsPreAuthCode [delete]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) DeleteXhsPreAuthCode(c *gin.Context) {
	id := c.Query("id")
	err := xhsPreAuthCodeService.DeleteXhsPreAuthCode(id)
	if err != nil {
		global.MS_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteXhsPreAuthCodeByIds 批量删除xhsPreAuthCode表
// @Tags XhsPreAuthCode
// @Summary 批量删除xhsPreAuthCode表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /xhsPreAuthCode/deleteXhsPreAuthCodeByIds [delete]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) DeleteXhsPreAuthCodeByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	err := xhsPreAuthCodeService.DeleteXhsPreAuthCodeByIds(ids)
	if err != nil {
		global.MS_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateXhsPreAuthCode 更新xhsPreAuthCode表
// @Tags XhsPreAuthCode
// @Summary 更新xhsPreAuthCode表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsPreAuthCode true "更新xhsPreAuthCode表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /xhsPreAuthCode/updateXhsPreAuthCode [put]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) UpdateXhsPreAuthCode(c *gin.Context) {
	var xhsPreAuthCode xiaohongshu.XhsPreAuthCode
	err := c.ShouldBindJSON(&xhsPreAuthCode)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsPreAuthCodeService.UpdateXhsPreAuthCode(xhsPreAuthCode)
	if err != nil {
		global.MS_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindXhsPreAuthCode 用id查询xhsPreAuthCode表
// @Tags XhsPreAuthCode
// @Summary 用id查询xhsPreAuthCode表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketing.XhsPreAuthCode true "用id查询xhsPreAuthCode表"
// @Success 200 {object} response.Response{data=marketing.XhsPreAuthCode,msg=string} "查询成功"
// @Router /xhsPreAuthCode/findXhsPreAuthCode [get]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) FindXhsPreAuthCode(c *gin.Context) {
	id := c.Query("id")
	rexhsPreAuthCode, err := xhsPreAuthCodeService.GetXhsPreAuthCode(id)
	if err != nil {
		global.MS_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(rexhsPreAuthCode, c)
}

// GetXhsPreAuthCodeList 分页获取xhsPreAuthCode表列表
// @Tags XhsPreAuthCode
// @Summary 分页获取xhsPreAuthCode表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsPreAuthCodeSearch true "分页获取xhsPreAuthCode表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /xhsPreAuthCode/getXhsPreAuthCodeList [get]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) GetXhsPreAuthCodeList(c *gin.Context) {
	var pageInfo xiaohongshuReq.XhsPreAuthCodeSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := xhsPreAuthCodeService.GetXhsPreAuthCodeInfoList(pageInfo)
	if err != nil {
		global.MS_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetXhsPreAuthCodePublic 不需要鉴权的xhsPreAuthCode表接口
// @Tags XhsPreAuthCode
// @Summary 不需要鉴权的xhsPreAuthCode表接口
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsPreAuthCodeSearch true "分页获取xhsPreAuthCode表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /xhsPreAuthCode/getXhsPreAuthCodePublic [get]
func (xhsPreAuthCodeApi *XhsPreAuthCodeApi) GetXhsPreAuthCodePublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	xhsPreAuthCodeService.GetXhsPreAuthCodePublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的xhsPreAuthCode表接口信息",
	}, "获取成功", c)
}
